package com.hmall.web;


import com.hmall.common.dto.PageDTO;
import com.hmall.pojo.ItemDoc;

import com.hmall.pojo.RequestParams;
import com.hmall.service.ItemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @Author dml
 * Date on 2022/7/11 0011
 */



@RestController
@RequestMapping("/search")
public class HmallController {

    @Autowired
    private ItemSearchService itemSearchService;

    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams requestParams){
        return itemSearchService.searchPage(requestParams);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filter(@RequestBody RequestParams requestParams){
        return itemSearchService.filters(requestParams);

    }

    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix){
        return itemSearchService.getSuggestion(prefix);
    }

}
